<?php

namespace app\admin\model\xilujob;

use app\admin\model\User;
use think\Exception;
use think\Model;
use traits\model\SoftDelete;

class Resume extends Model
{

    use SoftDelete;


    protected $moduleClasses;
    // 表名
    protected $name = 'xilujob_resume';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text',
        'black_text'
    ];

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getBlackList()
    {
        return ['0' => __('Black 0'), '1' => __('Black 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBlackTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['black']) ? $data['black'] : '');
        $list = $this->getBlackList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user() {
        return $this->belongsTo(User::class, 'user_id','id',[],'LEFT')->setEagerlyType(0);
    }
    /**
     * 个人信息
     */
    public function personal() {
        return $this->hasOne(ResumePersonalInfo::class,'resume_id','id',[],'LEFT')->setEagerlyType(0);
    }

    /**
     * 求职意向
     */
    public function jobIntention() {
        return $this->hasOne('ResumeJobIntention', 'resume_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 教育经历
     */
    public function educations() {
        return $this->hasMany('ResumeEducation', 'resume_id', 'id')->order('start','desc');
    }
    /**
     * 工作经历
     */
    public function works() {
        return $this->hasMany('ResumeWork', 'resume_id', 'id')->order('start','desc');
    }

    /**
     * 技能
     */
    public function skills() {
        return $this->hasMany('ResumeSkill', 'resume_id', 'id');
    }

    /**
     * 个人总结
     */
    public function summary() {
        return $this->hasOne('ResumeSummary', 'resume_id', 'id', [], 'LEFT');
    }

    /**
     * 个人标签
     */
    public function personalTags() {
        return $this->belongsToMany(ResumePersonalTag::class, ResumePersonalTagRelation::class, 'tag_id','resume_id');
    }

}
